﻿using Nest;
using System;

namespace EsSample
{
    public class ReadService
    {
        public static ISearchResponse<dynamic> GetLogList()
        {
            var index = "logstash-2021.01.26-000001";
            var client = EsClientFactory.GetClient;

            var result = client.Search<dynamic>(s => s
                .Index(index)
                .From(0)
                .Size(10)
                .MatchAll()
                .Query(q => q
                    .Bool(b => b
                        .Filter(f =>
                            f.DateRange(dr => dr
                                .Field("@timestamp").GreaterThanOrEquals(new DateTime(2021, 01, 20)))
                            )
                        .Must(m => m.Terms(t => t
                              .Name("named_query")
                              .Field("username")
                              .Terms("chenw")))
                    )
                )
            );
            return result;
        }
    }
}